template: Add break_words option to fill function - #10079
template: Add break_words option to fill function#10079genericusername2709 wants to merge 1 commit into
break_words option to fill function#10079Conversation
There was a problem hiding this comment.
The following commits do not follow our format for subject lines:
- 4bc0d67: Add an option of specifying if we want to break words when using fill function in jj log template
Commits should have a subject line following the format <topic>: <description>. Please review the commit guidelines for more information.
4bc0d67 to
34f1191
Compare
All commits are now correctly formatted. Thank you for your contribution!
34f1191 to
ee286d1
Compare
josephlou5
left a comment
There was a problem hiding this comment.
Do you maybe need a changelog entry?
Also, move explanation of the change (not just "how to test") into the commit description per https://docs.jj-vcs.dev/latest/contributing/#commit-guidelines.
|
Also your commit subject is a bit long :) Suggestion:
Note that these template functions can be used in many commands, not just |
|
Generally, please do not use booleans as a parameters. This is the Boolean Blindness anti-pattern. This makes the template more descriptive and the effect/intent is obvious to a reader. It also avoids confusion if there is more than one boolean argument: As a bonus it is more flexible for future changes, e.g. add more "modes" like justifying, breaking with a dash "-", ... |
There neither are constants or enums in the template language, so this will be hard. |
IIUC, the code looks for a named parameter here, so |
For completeness, this could be done, but I wouldn't recommend it: [template-aliases]
FILL_BREAK_WORDS = 'true'
'format_commit(commit)' = '''
fill(50, commit.description(), FILL_BREAK_WORDS)
'''Any user could come by and override their own You could also: [template-config]
# This table doesn't exist in the schema, but you can define whatever you want
# in your config; jj does not error in this case (yet).
fill_break_words = true
[template-aliases]
'format_commit(commit)' = '''
fill(50, commit.description(), config("template-config.fill_break_words").as_boolean())
'''But this moves function arguments into a config, which sounds weird. FWIW I do use this pattern in some of my template aliases for "default function arguments", but I don't think it makes sense for the upstream project to ship with this pattern. |
For public Rust functions, I agree. Maybe we can add a separate step for splitting long words? We can also add a dedicated template function for this step (instead of extending |
break_words option to fill function
Adding new functions for each variation in functionality can spiral into a bloated function list quickly. Added a test for a template that uses the named param |
584ec9b to
0f62867
Compare
This change adds a optional bool param to the globally available fill function in templating DSL to allow users to specify if they want to split words if the size of any word in the input is greater than the `width` passed to the function. Current supported template: `jj log --template "fill($(($(tput cols) - 8)), self.description()) ++ \"\n\""` After this change: (The original keeps being supported) `jj log --template "fill($(($(tput cols) - 8)), self.description(), break_words=true) ++ \"\n\""
0f62867 to
337e871
Compare

Add an option of specifying if we want to break words when using fill function in jj log template
Sample template to test:
jj log --template "fill(89, self.description()) ++ \"\n\""Added functionality to allow breaking words that are longer than the length passed in fill function in jj log templates
WHY: To allow proper rendering of commit messages on thin terminal windows using custom templates.
Checklist
If applicable:
README.md,docs/,demos/)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant. This includes,
for example, commit descriptions, PR descriptions, and code comments.